package me.send.data.service.mapper;

import java.util.List;
import java.util.Map;

import me.send.data.service.BaseMapper;
import me.send.data.service.pojo.Orders;
import me.send.data.service.provider.OrdersProvider;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;

public abstract interface OrdersMapper extends BaseMapper {

	/**
	 * 分页查询 接口
	 * 
	 * 2015-6-18 15:52:36
	 */

	@SelectProvider(method = "list_page", type = OrdersProvider.class)
	@Results( {
			// 使用userid 可能以后要展示userid
			@Result(column = "userid", property = "userid"),
			// 根据userid 查询user对象 主要是查询下面的nickname和userid
			@Result(column = "userid", property = "user", one = @One(select = user_mapper_all
					+ "map_userid")),
			// 使用status
			@Result(column = "status", property = "status"),
			@Result(column = "status", property = "orderstatus", one = @One(select = orderstatus_mapper_all
					+ "map_orderstatusid")),
			// 使用类型
			@Result(column = "ordertypeid", property = "ordertypeid"),
			@Result(column = "ordertypeid", property = "ordertype", one = @One(select = ordertype_mapper_all
					+ "map_ordertyeid")) })
	public abstract List<Map<String, Object>> orders_page(
			Map<String, Object> parameter);

	/**
	 * 使用带条件查询的时候
	 * 
	 * 查询的数目 2015年6月18日16:02:03
	 */
	@SelectProvider(method="ordersCount",type=OrdersProvider.class)
	public abstract int orders_count(Map<String, Object> parameter);
	
	
	@SelectProvider(method = "getOrders", type = OrdersProvider.class)
	public abstract List<Map<String, Object>> getOrders(Map<String, Object> params);

	/**
	 * 根据编号 删除功能 2015年6月18日18:09:55
	 */
	@Delete(value = "delete from orders where orderid = #{orderid}")
	public abstract void delete(String orderid);
	
	@Insert(value = "insert into orders(orderid,descption,createtime,getaddress,tip,sendaddress,userid,status,ordertypeid,tradtime,capital,"
			+ "address,longitude,latitude,voicepath,type,address_id,to_address_id,cityid,cityname,fee,discount,advert_id)"
			+ " values(#{orderid},#{descption},#{createtime},#{getaddress},#{tip},#{sendaddress},#{userid},"
			+ "#{status},#{ordertypeid},#{tradtime},#{capital},#{address},#{longitude},#{latitude},#{voicepath},#{type},"
			+ "#{addressId},#{toAddressId},#{cityid},#{cityname},#{fee},#{discount},#{advertId})")
	@Options(keyProperty="orderid",useGeneratedKeys=true)
	public abstract void releaseOrder(Orders orders);

}
